<template>
  <!-- /* 原材料出库 */ -->
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入名称" v-model="queryParam.itemName"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="出库日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-range-picker
                    style="width:100%"
                    v-model="queryParam.recordDate"
                    format="YYYY-MM-DD"
                    :placeholder="['开始时间', '结束时间']"
                    @change="onDateChange"
                    @ok="onDateOk"
                  />
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-top: 5px">
          <a-button @click="myHandleAdd(1)" type="primary" icon="plus">新增</a-button>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="{ x: 1000, y: 500 }"
            :loading="loading"
            @change="handleTableChange"
          >
            <span slot="action" slot-scope="text, record">
              <!-- <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" /> -->
              <a-popconfirm title="确定删除吗?" @confirm="() => myhandleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
            <span slot="remark" slot-scope="text, record">
              <a-tooltip>
                <template slot="title">
                  {{ record.remark }}
                </template>
                <div>{{ record.remark | ellipsis(10) }}</div>
              </a-tooltip>
            </span>
            <span slot="unqualifiedStock" slot-scope="text, record">
              <a-tag color="#87d068" v-if="record.unqualifiedStock == 0">合格</a-tag>
              <a-tag color="#f50" v-else>不合格</a-tag>
            </span>
            <template slot="customRenderStatus" slot-scope="status">
              <a-tag v-if="status == '0'" color="red">未审核</a-tag>
              <a-tag v-if="status == '1'" color="green">已审核</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <addMaterial ref="modalForm" @ok="modalFormOk"></addMaterial>
        <bill-detail ref="modalDetail"></bill-detail>
      </a-card>
    </a-col>
  </a-row>
</template>
<!--power by jisheng hua-->
<script>
// import DisassembleModal from './modules/DisassembleModal'
import addMaterial from './modules/addMaterial'
import BillDetail from './dialog/BillDetail'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { BillListMixin } from './mixins/BillListMixin'
import JDate from '@/components/jeecg/JDate'
import { getAction, deleteAction } from '@/api/manage'
import Vue from 'vue'
export default {
  name: 'ExRawmaterial',
  mixins: [JeecgListMixin, BillListMixin],
  components: {
    addMaterial,
    BillDetail,
    JDate
  },
  data() {
    return {
      // 查询条件
      queryParam: {
        number: '',
        materialParam: '',
        type: '其它',
        subType: '拆卸单',
        roleType: Vue.ls.get('roleType'),
        depotId: '',
        creator: ''
      },
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      // 表头
      columns: [
        // { title: '序号', dataIndex: 'serialNum', width: 90, align: 'center' },
        {
          title: '单据编号',
          dataIndex: 'itemNum',
          width: 160,
          align: 'center',
          customRender: function(text, record, index) {
            if (record.linkNumber) {
              return text + '[转]'
            } else {
              return text
            }
          }
        },
        { title: '批号', dataIndex: 'batchNumber', width: 145, align: 'center' },
        { title: '供应商', dataIndex: 'supplier', width: 145, align: 'center' },
        { title: '名称', dataIndex: 'itemName', width: 145, align: 'center' },
        { title: '规格', dataIndex: 'specifications', width: 145, align: 'center' },
        { title: '单位', dataIndex: 'unit', width: 145, align: 'center' },
        { title: '数量', dataIndex: 'quantity', width: 145, align: 'center' },
        // { title: '单价', dataIndex: 'price', width: 145,align: 'center' },
        { title: '日期', dataIndex: 'recordDate', width: 145, align: 'center' },
        // { title: '总金额', dataIndex: 'totalAmount',align: 'center' },
        {
          title: '是否合格',
          dataIndex: 'unqualifiedStock',
          align: 'center',
          width: 80,
          scopedSlots: { customRender: 'unqualifiedStock' }
        },
        { title: '用途', dataIndex: 'purpose', width: 145, align: 'center' },
        { title: '出库负责人', dataIndex: 'principal', align: 'center', width: 120 },
        { title: '仓库管理人', dataIndex: 'depotManager', align: 'center', width: 120 },
        { title: '备注', dataIndex: 'remark', align: 'center', width: 120, scopedSlots: { customRender: 'remark' } },
        {
          title: '状态',
          dataIndex: 'status',
          width: 80,
          align: 'center',
          scopedSlots: { customRender: 'customRenderStatus' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 120,
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/depotRecord/page/record?recordType=' + 1 + '&itemType=' + 2,
        delete: '/depotRecord/remove',
        deleteBatch: '/depotHead/deleteBatch',
        batchSetStatusUrl: '/depotHead/batchSetStatus'
      }
    }
  },
  computed: {},
  created() {
    this.getDepotData()
    this.initUser()
    this.getDictionary()
  },
  methods: {
    onDateChange: function(value, dateString) {
      this.queryParam.startTime = dateString[0]
      this.queryParam.endTime = dateString[1]
      console.log(this.queryParam)
    },
    getDictionary() {
      getAction('/generalDict/getList', { codeType: 'depotType' }).then(res => {
        console.log(res)
      })
    },
    myhandleDelete: function(id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      var that = this
      deleteAction(that.url.delete, { id: id }).then(res => {
        if (res.code === 200 || res.code === 10000) {
          that.loadData()
        } else {
          that.$message.warning(res.data.message)
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
